package com.my.helper.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 项目名称：WindFarm_Check 类名称： SharedPrefUtil 创建人：
 * 类描述：文件存储工具
 */
public class SharedPrefUtil {

	private Editor mEditor;
	private SharedPreferences mSharedPreferences;

	public SharedPrefUtil(Context context, String name) {
		mSharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
		mEditor = mSharedPreferences.edit();
	}

	public void putString(String key, String value) {
		mEditor.putString(key, value);
	}

	public void putInt(String key, int value) {
		mEditor.putInt(key, value);
	}

//	public void putDouble(String key, double d) {
//		mEditor.putFloat(key, (float) d);
//	}

	public void putLong(String key, long value) {
		mEditor.putLong(key, value);
	}

	public void putBoolean(String key, boolean value) {
		mEditor.putBoolean(key, value);
	}

	public int getInt(String key, int defaultValue) {
		return mSharedPreferences.getInt(key, defaultValue);
	}

	public boolean getBoolean(String key, boolean defaultValue) {
		return mSharedPreferences.getBoolean(key, defaultValue);
	}

//	public double getDouble(String key, double defaultValue) {
//		// return mSharedPreferences.getFloat(key, (float) defaultValue);
//		return Double.parseDouble(String.valueOf(mSharedPreferences.getFloat(key, (float) defaultValue)));
//	}

	public long getLong(String key, long defaultValue) {
		return mSharedPreferences.getLong(key, defaultValue);
	}

	public String getString(String key, String defaultValue) {
		return mSharedPreferences.getString(key, defaultValue);
	}

	public void commit() {
		mEditor.commit();
	}

	public void delete(String key) {
		mEditor.remove(key);
	}

	public void clear() {
		mEditor.clear();
		mEditor.commit();
	}
}
